﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
using Common;

namespace SERS.ExamRoom
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string json = GetAllExam();
                List<ExamRoomList> list = new List<ExamRoomList>();
                if (!string.IsNullOrEmpty(json))
                {
                    hidExams.Value = json;
                    list = JsonConvert.DeserializeObject<List<ExamRoomList>>(json);
                    if (list != null && list.Count > 0)
                    {
                        string ids = "";
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (i == 0)
                            {
                                ids = list[i].id.ToString();
                            }
                            else
                            {
                                ids += "|" + list[i].id;
                            }
                        }
                        hidExamIdList.Value = ids;
                        hidExamMaxId.Value = list.OrderByDescending(p => p.id).FirstOrDefault().id.ToString();
                    }
                }
            }
        }

        /// <summary>
        /// 获取所有模拟题库
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public string GetAllExam()
        {
            Service client = new Service();
            string _path = Server.MapPath("Exam\\Exam.txt");
            string str = client.ReaderTxt(_path);
            return str;
        }
    }

}